package qsc.datastructure.tree.binarytree;

import qsc.datastructure.tree.Node;

/**
 * @auther QiuShangcheng
 * @create 2021/4/14
 */
public class Client {
    public static void main(String[] args) {
        Node root = new Node(1, "zs");
        Node node1 = new Node(2, "ls");
        Node node2 = new Node(3, "ww");
        Node node3 = new Node(4, "zl");
        Node node4 = new Node(5, "xh");
        BinaryTree binaryTree = new BinaryTree(root);
        root.setLeft(node1);
        root.setRight(node2);
        node2.setLeft(node4);
        node2.setRight(node3);
        binaryTree.setRoot(root);
        System.out.println("高度为：");
        int height = root.height();
        System.out.println(height);
        System.out.println("前序遍历");
        if (root != null){
            root.preOrder();
        }else throw new NullPointerException("空指针了");
        System.out.println("中序遍历");
        if (root != null){
            root.infixOrder();
        }else throw new NullPointerException("空指针了");
        System.out.println("后序遍历");
        try {
            if (root != null){
                root.postOrder();
            }else throw new NullPointerException("空指针了");
        } catch (Exception e) {
           e.printStackTrace();
        }

        System.out.println("前序查找");
        Node node = root.preSelect(5);
        System.out.println(node);
        System.out.println("中序查找");
        Node tree2 = root.preSelect(3);
        System.out.println(tree2);
    }
}
